package threshold
import (
"github.com/K-Phoen/sdk"
)
type Mode string
const (
Percentage Mode = "percentage"
Absolute Mode = "absolute"
)
type DisplayStyle string
const (
Off DisplayStyle = "off"
AsFilledRegions DisplayStyle = "area"
AsLines DisplayStyle = "line"
Both DisplayStyle = "line+area"
)
type Option func (threshold *Threshold )
type Step struct {
Color string
Value float64
}
type Threshold struct {
baseColor string
fieldConfig *sdk .FieldConfig
}
func New (fieldConfig *sdk .FieldConfig , options ...Option ) *Threshold {
threshold := &Threshold {fieldConfig : fieldConfig }
defaultOpts := []Option {
Style (AsLines ),
ValueMode (Absolute ),
BaseColor ("green" ),
}
for _ , opt := range append (defaultOpts , options ...) {
opt (threshold )
}
return threshold
}
func Style (style DisplayStyle ) Option {
return func (thresholds *Threshold ) {
thresholds .fieldConfig .Defaults .Custom .ThresholdsStyle .Mode = string (style )
}
}
func BaseColor (color string ) Option {
return func (thresholds *Threshold ) {
thresholds .baseColor = color
}
}
func ValueMode (mode Mode ) Option {
return func (thresholds *Threshold ) {
thresholds .fieldConfig .Defaults .Thresholds .Mode = string (mode )
}
}
func Steps (steps ...Step ) Option {
return func (thresholds *Threshold ) {
sdkSteps := make ([]sdk .ThresholdStep , 0 , len (steps ))
for i := range steps {
sdkSteps = append (sdkSteps , sdk .ThresholdStep {
Color : steps [i ].Color ,
Value : &steps [i ].Value ,
})
}
thresholds .fieldConfig .Defaults .Thresholds .Steps = append (
[]sdk .ThresholdStep {{Color : thresholds .baseColor }},
sdkSteps ...,
)
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .